package com.wn.quality.web.rabbitmq;

import com.rabbitmq.client.Channel;
import com.wn.entity.Nonconformance;
import com.wn.quality.service.NonconformanceService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author wuqingting
 * @date 2022/10/20
 */
@Component
public class Consumer {
    @Autowired
    private NonconformanceService nonconformanceService;

    @RabbitListener(queues = "ncrAddQueue")
    public void ncrAddQueue(Nonconformance nonconformance, Message message, Channel channel){
        nonconformanceService.add(nonconformance);
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
